import { defineStore } from 'pinia'
import { ref } from 'vue'
import { storeAPI, categoryAPI } from '@/api'

export const useAppStore = defineStore('app', () => {
  const storeInfo = ref({})
  const categories = ref([])
  const loading = ref(false)

  // Load store info
  const loadStoreInfo = async () => {
    try {
      loading.value = true
      const response = await storeAPI.getInfo()
      if (response.success) {
        storeInfo.value = response.data
      }
    } catch (error) {
      console.error('Failed to load store info:', error)
    } finally {
      loading.value = false
    }
  }

  // Load categories
  const loadCategories = async () => {
    try {
      const response = await categoryAPI.getAll()
      if (response.success) {
        categories.value = response.data
      }
    } catch (error) {
      console.error('Failed to load categories:', error)
    }
  }

  return {
    storeInfo,
    categories,
    loading,
    loadStoreInfo,
    loadCategories
  }
})

